package com.zy.qudadid.presenter;

import com.zy.qudadid.model.PayList;
import com.zy.qudadid.model.PayListAfter;
import com.zy.qudadid.model.Res;
import com.zy.qudadid.network.Const;
import com.zy.qudadid.network.Net;
import com.zy.qudadid.presenter.base.BasePresenterImp;
import com.zy.qudadid.ui.view.IndexBillingView;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by ninos on 2016/7/30.
 */
public class IndexBillingPresenter extends BasePresenterImp<IndexBillingView> {
    //    /api.php?c=infoOrderCar&a=beforepay_list&args=
    public void beforepay(String data) {
        Subscription subscription = Net.getService()
                .beforepay("infoOrderCar", "beforepay_list", data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res<PayList>>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.errorf();
                    }

                    @Override
                    public void onNext(Res<PayList> res) {
                        if (res.code == Const.OK) {
                            view.successf(res.datas);
                        } else {
                            view.errorf();
                        }
                    }
                });

        addSubscription(subscription);
    }
    //    {$api_url}/api.php?c=infoOrderCar&a=give5fee&args=
    public void givefee(String data) {
        Subscription subscription = Net.getService()
                .givefee("infoOrderCar", "give5fee", data)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Res<PayListAfter>>() {

                    @Override
                    public void onCompleted() {
                    }

                    @Override
                    public void onError(Throwable e) {
                        view.errors();
                    }

                    @Override
                    public void onNext(Res<PayListAfter> res) {
                        if (res.code == Const.OK) {
                            view.successs(res.datas);
                        } else {
                            view.errors();
                        }
                    }
                });

        addSubscription(subscription);
    }
}
